package com.qf.test;

import com.qf.dao.UserMapper;

import com.qf.pojo.TbUser;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/8/23 11:09
 */

public class Demo {
    @Test
    public void test01(){
        try {
//            读取配置文件
            InputStream inputStream= Resources.getResourceAsStream("mybatis.xml");
//           创造sqlsession工厂对象
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
//           开启工厂
            SqlSession sqlSession = sqlSessionFactory.openSession();
//            通过类对象调用数据库管理层(DAO)的方法
            UserMapper userMapper=sqlSession.getMapper(UserMapper.class);
            TbUser tbUser = userMapper.selectTbUser(7L);
            System.out.println("tbUser = " + tbUser);
//           关闭工厂
            sqlSession.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
